/*
package com.healthcloud.listener;

import cn.jiguang.common.resp.APIRequestException;
import cn.jpush.api.bean.TestDateEntity;
import cn.jpush.api.push.PushClient;
import cn.jpush.api.push.PushResult;
import cn.jpush.api.push.model.Options;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import cn.jpush.api.push.model.notification.Notification;
import com.alibaba.fastjson.JSON;
import com.healthcloud.constants.StringConsts;
import com.healthcloud.pojo.TestResult;
import com.healthcloud.service.BusInstrumentService;
import com.healthcloud.service.JpushInfoService;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.ChannelAwareMessageListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

*/
/**
 *
 * poct类消费监听器
 * @Author yucl
 * @date 2018/7/30
 *//*

@Component
@Slf4j
public class PoctListener implements  ChannelAwareMessageListener {

    @Autowired
    private BusInstrumentService busInstrumentService;

    @Autowired
    private JpushInfoService jpushInfoService;

//    @RabbitListener(queues = "poctQueue")
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        try {
            log.info("ACK");
            log.info(new String(message.getBody()));
            Object object = JSON.parse(new String(message.getBody()));
            TestDateEntity testDateEntity = JSON.parseObject(object.toString(),TestDateEntity.class);
            //推送消息
            log.info("start jpush");

            PushClient _client = new PushClient(StringConsts.MASTER_SECRET, StringConsts.APP_KEY);

            String alert = "SMART Ⅳ有一条新检测结果！设备SN：["+testDateEntity.getMKMedicalinstrumentId()+"]。查看详情＞＞。";

            List<String> openIDs = busInstrumentService.getOpenID(testDateEntity.getMKMedicalinstrumentId());

            PushPayload payload = PushPayload.newBuilder()
                    .setPlatform(Platform.all())
                    .setAudience(Audience.alias(openIDs))
                    .setNotification(Notification.alert(alert))
                    .setOptions(Options.newBuilder()
                            .setApnsProduction(true)
                            .build())
                    .build();

            PushResult result = new PushResult();
            try {

                //保存到病人表
                jpushInfoService.savePatient(testDateEntity);

                //保存到推送表
                jpushInfoService.saveJpushInfoEntity(testDateEntity,testDateEntity.getMKMedicalinstrumentId());


                result = _client.sendPush(payload);

            } catch (APIRequestException e) {
                e.printStackTrace();
                log.error(e.getErrorMessage());

            }

            channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
        }catch (Exception e){
            log.error(e.getMessage());
            log.error("NACK");
            channel.basicNack(message.getMessageProperties().getDeliveryTag(), false, true);
        }
    }
}
*/
